﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace V2TEK.NET.SH.Silverlight.Charts
{
    /// <summary>
    /// 已完成百分比转化,由Data.PercentComplete转化为GridLength parameter=A，反之为parameter=B
    /// </summary>
    public class GridLengthConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                if (parameter == null)
                    parameter = "A";
                switch (parameter.ToString())
                {
                    case "A":
                        return new GridLength(double.Parse(value.ToString()) * 0.01, GridUnitType.Star);
                    case "B":
                        return new GridLength(1 - double.Parse(value.ToString()) * 0.01, GridUnitType.Star);
                }
            }
            catch
            {
            }

            return new GridLength(1, GridUnitType.Star);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    /// <summary>
    /// Data.PercentComplete转化为 %
    /// </summary>
    public class PercentConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                return value.ToString() + "%";
            }
            catch
            {
            }

            return "";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
